<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button class="start">开始</button>
    <button class="stop">停止</button>
    <script>
      var start = document.querySelector(".start");
      var stop = document.querySelector(".stop");
      var timer = null;
      start.addEventListener("click", function () {
        timer = setInterval(function () {
          console.log("bom");
        }, 1000);
      });
      stop.addEventListener("click", function () {
        clearInterval(timer);
      });
    </script>
  </body>
</html>
